package com.zhima.controller.feign;

import com.zhima.dto.CreateOjUserDTO;
import com.zhima.dto.UserDTO;
import com.zhima.dto.UserDTOExtension;
import com.zhima.service.OjUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhima
 * @since 2023-08-23
 */
@RestController
@RequestMapping("/user/feign")
public class OjUserFeignController {
    @Autowired
    private OjUserService ojUserService;

    /**
     * 根据{userName}获取指定用户拥有的资源code集合
     *
     * @return
     */
    @GetMapping("/auth-info/u/{userName}")
    public UserDTOExtension authInfo(@PathVariable("userName") String userName) {
        return ojUserService.queryUserDetailWithResourcesByUserName(userName);
    }

    /**
     * 根据{email}获取指定用户拥有的资源code集合
     *
     * @param email
     * @return
     */
    @GetMapping("/auth-info/e/{email}")
    public UserDTOExtension authInfoByEmail(@PathVariable("email") String email) {
        return ojUserService.queryUserDetailWithResourcesByUserEmail(email);
    }

    /**
     * 根据{phone}获取指定用户拥有的资源code集合
     *
     * @param phone
     * @return
     */
    @GetMapping("/auth-info/p/{phone}")
    public UserDTOExtension authInfoByPhone(@PathVariable("phone") String phone) {
        return ojUserService.queryUserDetailWithResourcesByUserPhone(phone);
    }

    /**
     * 创建普通用户
     *
     * @param ojUser
     * @return
     */
    @PostMapping
    public UserDTOExtension createPlainUser(@RequestBody CreateOjUserDTO ojUser) {
        return ojUserService.createPlainUser(ojUser);
    }

    /**
     * 根据{userId}获取指定用户信息
     *
     * @param userId
     * @return
     */
    @GetMapping("/{userId}")
    public UserDTO basicInfoById(@PathVariable("userId") Long userId) {
        return ojUserService.queryUserBasicInfoById(userId);
    }
}
